var treeObj;
var chartEC;

$(function() {
		tree_init();
});

// tree初始化
var tree_init = function() {
	// 获取油气井数据
	$.ajax({
		url : '/gas/dynamic/tree/tree',
		dataType : 'json',
		success:function(data) {
			if (!data) {
				return;
			}

			// 初始化树
			var settings = {
				treeId : "mytree",
				view : {
					//selectedMulti: false,
					showIcon : false,
					
					fontCss : {
//						font_size : "15px"
					}
				},
				check : {
					enable : true,
					chkStyle:"checkbox",
					chkboxType: { "Y": "", "N": "" }
				},
				callback : {
					onClick : myOnClick,
					onCheck : myOnCheck
				}
			};

			treeObj = $.fn.zTree.init($('#xzqtree'), settings, data);

			// 节点点击的处理
			function myOnClick(event, treeId, treeNode) {
				//alert(treeNode.wellcode+"||"+treeNode.text+"||"+treeNode.id);
//				treeObj.cancelSelectedNode();
//				if (treeNode.chkDisabled == false) {
	//
//					if (treeNode.checked == true) {
//						treeNode.checked = false;
//					} else {
//						treeNode.checked = true;
//					}
//				}
				var nodes = treeObj.getCheckedNodes();
				if (nodes.length>0) { 
					nodes[0].checked = false;
					treeObj.updateNode(nodes[0]);
				}
				treeNode.checked = true;
				treeObj.updateNode(treeNode);
				//判断是否为井组、区块、或者气田
				var Wellcode=treeNode.wellcode;
				if(Wellcode.substring(6,Wellcode.length)=='0000'){
					AxisDou(Wellcode);//
				}else{
					AxisSin(Wellcode);
				}


			};
			// 节点checked的处理
			function myOnCheck(event, treeId, treeNode) {
				var nodes = treeObj.getCheckedNodes();
				for(var i=0;i<nodes.length;i++) { 
					nodes[i].checked = false;
					treeObj.updateNode(nodes[i]);
				}
				treeNode.checked = true;
//				treeObj.updateNode(treeNode);
				//alert(treeNode.wellcode+"||"+treeNode.text+"||"+treeNode.id);
				//判断是否为井组、区块、或者气田
				var Wellcode=treeNode.wellcode;
				if(Wellcode.substring(6,Wellcode.length)=='0000'){
					AxisDou(Wellcode);//
				}else{
					AxisSin(Wellcode);
				}

			};

		}
	});
}
//井组区块横纵坐标
function AxisDou(Wellcode){
	
//	alert(Wellcode);
	$("#zhibiao1").html("");
	$("#zhibiao1").html("<option value='PWF' name='井底流压(Mpa)' selected='selected'>井底流压</option>"
			+"<option value='QQ' name='日产气(m3)' >日产气</option>"
			+"<option value='LJCQ' name='累产气(m3)'>累产气</option>"
			+"<option value='QL' name='日产液(m3)'>日产液</option>"
			+"<option value='LJCY' name='累产液(m3)'>累产液</option>");
	$("#zhibiao2").html("");
	$("#zhibiao2").html("<option value='PWF' name='井底流压(Mpa)' selected='selected'>井底流压</option>"
			+"<option value='QQ' name='日产气(m3)' >日产气</option>"
			+"<option value='LJCQ' name='累产气(m3)'>累产气</option>"
			+"<option value='QL' name='日产液(m3)'>日产液</option>"
			+"<option value='LJCY' name='累产液(m3)'>累产液</option>");
}

//单井横纵坐标
function AxisSin(Wellcode){
	
//	alert(Wellcode);
	$("#zhibiao1").html("");
	$("#zhibiao1").html("<option value='PWF' name='井底流压(Mpa)' >井底流压</option>"
			+"<option value='QQ' name='日产气(m3)' >日产气</option>"
			+"<option value='LJCQ' name='累产气(m3)'>累产气</option>"
			+"<option value='QL' name='日产液(m3)' selected='selected'>日产液</option>"
			+"<option value='LJCY' name='累产液(m3)'>累产液</option>");
	$("#zhibiao2").html("");
	$("#zhibiao2").html("<option value='PWF' name='井底流压(Mpa)' >井底流压</option>"
			+"<option value='QQ' name='日产气(m3)' selected='selected'>日产气</option>"
			+"<option value='LJCQ' name='累产气(m3)'>累产气</option>"
			+"<option value='QL' name='日产液(m3)'>日产液</option>"
			+"<option value='LJCY' name='累产液(m3)'>累产液</option>");
}
